package org.nnxy.foodboot.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.RequiredArgsConstructor;
import org.nnxy.foodboot.entity.Recipe;
import org.nnxy.foodboot.entity.RecommendationRecord;
import org.nnxy.foodboot.service.RecommendationService;
import org.nnxy.foodboot.service.RecommendationRecordService;
import org.nnxy.foodboot.service.UserRecipeInteractionService;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.nnxy.foodboot.common.Result;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 推荐系统控制器
 */

@RestController
@RequestMapping("/api/recommendation")
@RequiredArgsConstructor
public class RecommendationController {
    

    private final RecommendationRecordService recommendationRecordService;




    /**
     * 分页查询食谱列表
     */
    @GetMapping("/page")
    public Map<String, Object> page(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String userId) {

        // 构建查询条件
        LambdaQueryWrapper<RecommendationRecord> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.hasText(userId)) {
            queryWrapper.like(RecommendationRecord::getUserId, userId);
        }


        // 按创建时间降序排序
        queryWrapper.orderByDesc(RecommendationRecord::getCreatedTime);

        // 分页查询
        Page<Recipe> page = recommendationRecordService.selectPage(current, size, userId);

        Map<String, Object> result = new HashMap<>();
        result.put("code", 200);
        result.put("data", page);
        return result;
    }

} 